package com.ziyia.a4_5_2;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;

import com.ziyia.a4_5_2.databinding.FragmentBookDatailBinding;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity implements BookListFragment.Callbacks {

    boolean mTwoPane;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (findViewById(R.id.framelayout) != null) {
            mTwoPane = true;
        }

    }

    @Override
    public void onItemSelected(int id) {


        if (mTwoPane) {
            Bundle bundle = new Bundle();
            bundle.putInt(BookDetailFragment.ITEM_ID, id);
            BookDetailFragment fragment = new BookDetailFragment();
            fragment.setArguments(bundle);
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.framelayout, fragment)
                    .commit();
        } else {
            Intent intent = new Intent(this, MainActivity2.class);
            intent.putExtra(BookDetailFragment.ITEM_ID, id);
            startActivity(intent);
        }
    }
}